#ifndef _SOFT_I2C_H
#define _SOFT_I2C_H

/* Private macros ------------------------------------------------------------*/
/**
 * @brief  subject to the hardware circuit, user should set the communication line of I2C as small as possible,
 *         user can decrease this time to decrease the time of reading data
 */
#define IIC_Delay_Time 20

#include "stdint.h"
#include "fsl_gpio.h"

typedef struct
{
    /* data */
    GPIO_Type* scl_base;
    uint32_t scl_pin;
    GPIO_Type* sda_base;
    uint32_t sda_pin;
}IIC_t;


void xSDA_IN(IIC_t* iic);
void xSDA_OUT(IIC_t* iic);
void xIIC_SCL(IIC_t* iic,const char x) ;
void xIIC_SDA(IIC_t* iic,const char x);
uint8_t xREAD_SDA(IIC_t* iic);
void IIC_Delay(uint8_t m);
void IIC_Init(IIC_t* iic);
void IIC_Start(IIC_t* iic);
void IIC_Stop(IIC_t* iic);
void IIC_Send_Byte(IIC_t* iic,unsigned char txd);
unsigned char IIC_Read_Byte(IIC_t* iic,unsigned char ack);
unsigned char IIC_Wait_Ack(IIC_t* iic);
void IIC_Ack(IIC_t* iic);
void IIC_NAck(IIC_t* iic);
unsigned char IIC_Device_Write_Byte(IIC_t* iic,unsigned char addr, unsigned char reg, unsigned char data);
unsigned char IIC_Device_Read_Byte(IIC_t* iic,unsigned char addr, unsigned char reg);
unsigned char IIC_Device_Write_Len(IIC_t* iic,unsigned char addr, unsigned char reg, unsigned char len, unsigned char *buf);
unsigned char IIC_Device_Read_Len(IIC_t* iic,unsigned char addr, unsigned char reg, unsigned char len, unsigned char *buf);
uint8_t SCCB_Device_Write(IIC_t* iic,unsigned char addr, unsigned char reg,unsigned char data);
uint8_t SCCB_Device_Read(IIC_t* iic,unsigned char addr, unsigned char reg);
uint16_t SCCB_Device_Read16bit(IIC_t* iic,unsigned char addr, unsigned char reg);
uint8_t SCCB_Device_Write16bit(IIC_t* iic,unsigned char addr, unsigned char reg,uint16_t data);
#endif
